<template>
	<el-dialog v-model="props.changeVisible" :title="props.title" width="40%" :before-close="() => close(false)">
		<div>
			<HyForm :hyFormConfig="hyFormConfig" :hyFormFields="hyFormFields" ref="hyFormRef" />
		</div>
		<template #footer>
			<div class="dialog-footer">
				<el-button @click="close(false)">取消</el-button>
				<el-button type="primary" @click="subumit" :loading="loading"> 确定 </el-button>
			</div>
		</template>
	</el-dialog>
</template>

<script setup lang="ts">
import HyForm from '/@/components/HyForm/index.vue';
import { meetingChangeApi } from '/@/api/expertDatabase/extract';
import { useDict } from '/@/hooks/dict';

const loading = ref(false);
// 定义字典
const { replacement_reason } = useDict('replacement_reason');
const props = defineProps({
	changeVisible: Boolean,
	title: {
		type: String,
		default: '',
	},
	ids: {
		type: Array,
		default: () => [],
	},
});
//动态表单配置
const hyFormConfig = computed(() => {
	return {
		labelWidth: '120px',
		type: 'submit',
	};
});
//配置基本信息表单
const hyFormFields = computed(() => {
	return {
		replacementReason: {
			label: `${props.title}理由`,
			type: 'select',
			required: true,
			options: replacement_reason.value,
		},
	};
});
//关闭
const emits = defineEmits(['close']);
const close = (isRefresh: boolean) => {
	emits('close', isRefresh);
};
//确定
const hyFormRef = ref();
const subumit = async () => {
	const result = await hyFormRef.value?.check();
	const params = {
		...hyFormRef.value.hyForm,
		ids: props.ids,
	};
	if (result) {
		loading.value = true;
		meetingChangeApi(params)
			.then(() => {
				close(true);
			})
			.finally(() => {
				loading.value = false;
			});
	}
};
</script>

<style scoped lang="scss"></style>
